sequenceDiagram
    title 服务购买-订单状态变更为已发起支付

    autonumber

    participant RabbitMQ

    participant DealerServicePurchaseOrderQueueListener
    participant DealerServicePurchaseOrderApplicationService
    participant DealerServicePurchaseOrderRepository
    participant PaymentOrderRepository
    participant DealerServicePurchaseOrder

    participant DomainEventPublisher


    RabbitMQ->>DealerServicePurchaseOrderQueueListener: 领域事件 PaymentInitiated
    DealerServicePurchaseOrderQueueListener->>DealerServicePurchaseOrderApplicationService: markAsPaymentInitiated()

    activate DealerServicePurchaseOrderApplicationService

    DealerServicePurchaseOrderApplicationService->>DealerServicePurchaseOrderRepository: findById(DealerServicePurchaseOrderId)
    activate DealerServicePurchaseOrderRepository

    DealerServicePurchaseOrderRepository-->>DealerServicePurchaseOrderApplicationService: DealerServicePurchaseOrder

    deactivate DealerServicePurchaseOrderRepository


    DealerServicePurchaseOrderApplicationService->>PaymentOrderRepository: findById(PaymentOrderId)
    activate PaymentOrderRepository

    PaymentOrderRepository-->>DealerServicePurchaseOrderApplicationService: PaymentOrder

    deactivate PaymentOrderRepository

    DealerServicePurchaseOrderApplicationService->>DealerServicePurchaseOrder: markAsPaymentInitiated(PaymentOrder)
    activate DealerServicePurchaseOrder
    DealerServicePurchaseOrder->>DealerServicePurchaseOrder: 基于自身和支付单验证是否可以设置为已发起支付
    DealerServicePurchaseOrder->>DealerServicePurchaseOrder: 更新内部数据状态
    DealerServicePurchaseOrder->>DomainEventPublisher: 发布领域事件 OrderPaymentInitiated
    deactivate DealerServicePurchaseOrder
    DealerServicePurchaseOrderApplicationService->>DealerServicePurchaseOrderRepository: save(DealerServicePurchaseOrder)

    deactivate DealerServicePurchaseOrderApplicationService


